package boogie.game.sound;

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;

/**
 *
 * @author Boogie
 */
public class Sound {

    private AudioClip sound;

    private class NullAudioClip implements AudioClip {

        @Override
        public void play() {
        }

        @Override
        public void loop() {
        }

        @Override
        public void stop() {
        }
    }

    public Sound(URL url) {

        try {
            sound = Applet.newAudioClip(url);
        } catch (Exception ex) {
            System.err.println("Loaded Null sound for URL:" + url);
            sound = new NullAudioClip();
        }
    }

    public void play() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                sound.play();
            }
        }).start();
    }

    public void loop() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                sound.loop();
            }
        }).start();
    }

    public void stop() {
        sound.stop();
    }

   
}
